#ifndef __OLED_H
#define __OLED_H
#include "iic_master.h"

#define OLED_GPIO_PIN_RST 4
#define OLED_PIN_SEL (1ULL << OLED_GPIO_PIN_RST)
#define OLED_CMD 0
#define OLED_DATA 1

/* 屏幕参数 */
#define BRIGHTNESS 0xCF //亮度
#define X_WIDTH 128     //宽度
#define Y_WIDTH 64      //长度
#define PAGE 8          //页数

/* 字库字体大小 */
#define FONTSIZE_12_6 12
#define FONTSIZE_16_8 16
#define FONTSIZE_32_16 32

#define MAX_CHAR_POSX X_WIDTH - 6 //字符宽度需要-6
#define MAX_CHAR_POSY Y_WIDTH - 6 //字符长度需要-6

#define BMP_MIX_MODE    0
#define BMP_COVER_MODE  1

#define POS_X(x) (x - 1)

/* 全局变量 缓冲区 */
extern uint8_t OLED_GRAM[128][8];

typedef struct _oled_fun
{
    /* 功能 */
    void (*init)(void);                     /* 初始化oled */
    void (*display_onoff)(uint8_t onoff);   /* oled 显示on/off */
    void (*set_light_level)(uint8_t level); /* 设置oled亮度等级 */
    void (*scoll_close)(void);
    void (*scroll_start)(uint8_t start, uint8_t end, uint8_t div_time, uint8_t lr);

    /* 绘制 */
    void (*drow_point)(uint8_t x, uint8_t y, uint8_t t);                             /* 画一个点 */
    void (*drow_line)(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t mode);    /* 画一条线 */
    void (*draw_rect)(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t mode);    /* 画一个矩形 */
    void (*show_char)(uint8_t x, uint8_t y, uint8_t ch, uint8_t size, uint8_t mode); /* 打印一个字符 */
    void (*show_number)(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t mode);
    void (*show_string)(uint8_t x, uint8_t y, const uint8_t *p, size_t size, uint8_t mode); /* 打印一个字符串 */
    /***********************************************************************
     *  函数名: oled_draw_bmp
     *  描述：以page为单位在缓冲区绘画一张bmp图片，速度快，但是不灵活(0-8) 融合的形式
     *  参数：uint8_t x 横坐标
     *  参数：uint8_t y 纵坐标(0-8)
     *  参数: uint8_t w bmp宽度(竖着总量/8)
     *  参数: uint8_t l bmp长度
     *  参数: uint8_t model 模式： 0 混合(融合)模式； 1：替换(覆盖))模式;
     *  参数：void *bmp bmp资源
     ***********************************************************************/
    void (*draw_bmp)(uint8_t x, uint8_t y, uint8_t w, uint8_t l, uint8_t model, void *bmp);      /* 以char绘制bmp */
    void (*draw_bmp_point)(uint8_t x, uint8_t y, uint8_t w, uint8_t l, uint8_t mode, void *bmp); /* 以bit绘制bmp */
    void (*draw_bmp_reversal)(uint8_t x, uint8_t y, uint8_t w, uint8_t l, uint8_t model, void *bmp);

    /* 刷新 */
    void (*clean_gram)(uint8_t data);                                                    /* 将缓存格式化为某个值 */
    void (*refresh_local)(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t mode); /* 局部刷新 */
    void (*refresh_all)(uint8_t mode);                                                   /* 全部刷新 */
} Oled_api;
extern Oled_api oled;

#endif